<?php


namespace App\Services\Result\Type;


use App\Models\Examination;
use App\Models\StudentResult;
use App\Models\User;
use App\Services\Result\BaseResult;
use Illuminate\Http\Request;

class DeficiencyResult extends BaseResult
{
    // 成绩分布统计
    public function show(Examination $testResult, Request $request)
    {
        parent::show($testResult,$request);

        // 缺考人员

        // 本次考试下的试卷列表
        $res = StudentResult::query()
            ->select('user_id')
            ->where('examination_id', $testResult)
            ->get()
            ->toArray();

        // 获取参与了考试的用户id数组
        $ids = array_unique(collect($res)->pluck('user_id')->toArray());

        // 所有需要参与考试的用户id数组
        $wantIds = $testResult->peoples;

        $data = [];
        foreach ($wantIds as $item) {
            if (!in_array($item, $ids)) {
                array_push($data, $item);
            }
        }

        $data = User::query()
            ->select('id','name','username','phone')
            ->with('section:id,name')
            ->whereIn('id',$data)
            ->get();


        return $data;
    }
}
